from src.kv_indexer import KVIndexer
from src.logging import get_logger

if __name__ == "__main__":
    # 初始化日志
    logger = get_logger("main")
    logger.info("Starting KV Cache Index Service")
    
    try:
        # 初始化KVIndexer服务
        indexer = KVIndexer()
        logger.info("KV Cache Index Service initialized successfully")
        
        # 使用KVIndexerService的事件循环阻塞主线程
        logger.info("Starting HTTP service in blocking mode. Press Ctrl+C to stop.")
        indexer.service.start_service(blocking=True)
        
    except KeyboardInterrupt:
        logger.info("Received keyboard interrupt, shutting down...")
    except Exception as e:
        logger.error("Failed to start KV Cache Index Service", error=str(e))
        raise
    finally:
        logger.info("KV Cache Index Service stopped")